import { http } from "@/utils/http";
import { baseUrlApi } from "@/api/utils";
import { message } from "@/utils/message";
type Result = {
	current_page : number;
	result ?: any;
	per_page ?: number;
	total ?: number;
	data ?: any;
};
type ResultDelete = {
	code : number;
	msg : string;
};
type ResultCreate = {
	code : number;
	msg : string;
};
type Show = {
	code : number;
	msg : string;
	result ?: any;
};
/** 客户列表 */
export const getCustomerListApi = (params ?: object) => {
	return http.request<Result>("get", "/customer/list", {
		params
	});
};
/** 客户添加*/
export const createCustomerApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/customer/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 客户修改 */
export const updateCustomerApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/customer/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 客户删除 */
export const delCustomerApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/customer/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 客户详情 */
export const getCustomerShowApi = (params ?: object) => {
	return http.request<Show>("get", "/customer/show", {
		params
	});
};


/*
*
*托盘
###################################################################
*/
/** 托盘列表 */
export const getPalletListApi = (params ?: object) => {
	return http.request<Result>("get", "/pallet/list", {
		params
	});
};
/** 托盘添加*/
export const createPalletApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/pallet/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 托盘修改 */
export const updatePalletApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/pallet/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 托盘删除 */
export const delPalletApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/pallet/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 托盘详情 */
export const getPalletShowApi = (params ?: object) => {
	return http.request<Show>("get", "/pallet/show", {
		params
	});
};

/*
*
*供应商
####################################################################
*/
/** 供应商列表 */
export const getSupplierListApi = (params ?: object) => {
	return http.request<Result>("get", "/supplier/list", {
		params
	});
};
/** 供应商添加*/
export const createSupplierApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/supplier/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 供应商修改 */
export const updateSupplierApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/supplier/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 供应商删除 */
export const delSupplierApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/supplier/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 供应商详情 */
export const getSupplierShowApi = (params ?: object) => {
	return http.request<Show>("get", "/supplier/show", {
		params
	});
};

/*
*
*货主
####################################################################
*/
/** 货主列表 */
export const getConsignorListApi = (params ?: object) => {
	return http.request<Result>("get", "/consignor/list", {
		params
	});
};
/** 货主添加*/
export const createConsignorApi = (data ?: object) => {
	return http.request<ResultCreate>("post", "/consignor/store", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 货主修改 */
export const updateConsignorApi = (data ?: object) => {
	return http.request<ResultCreate>("put", "/consignor/update", {
		data
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 货主删除 */
export const delConsignorApi = (params ?: object) => {
	return http.request<ResultDelete>("delete", "/consignor/delete", {
		params
	})
	.catch(error => {
		message(error.response.data.msg ?? "操作失败,请联系管理员", {
			type: "error"
		});
	});
};
/** 货主详情 */
export const getConsignorShowApi = (params ?: object) => {
	return http.request<Show>("get", "/consignor/show", {
		params
	});
};